<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/layer/3.0.1/skin/default/layer.min.css">
	
	<link rel="stylesheet" href="../../../adminlte/dist/css/AdminLTE.min.css">
	<link rel="stylesheet" href="../../../layui/css/layui.css">
	<link rel="stylesheet" href="../../../css/byking.css">
	<link rel="stylesheet" href="../../../adminlte/dist/css/skins/_all-skins.min.css">
</head>
<body onload="initpage()">
	<div class="byking-form">
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<input type="hidden" name="guid" id="guid">
			</div>
		
		
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">部门名称</label>
				<div class="layui-input-block">
					<input type="text" id="name" name="name" required lay-verify="required"
						placeholder="请输入部门名称" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">部门描述</label>
				<div class="layui-input-block">
					<input type="text" id="description" name="description" required lay-verify="required"
						placeholder="请输入部门描述" autocomplete="off" class="layui-input">
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:90px">部门图标</label>
				<div class="layui-input-block">
					<input type="text" id="image" name="image" required lay-verify="required"
						placeholder="请输入部门图标" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn " lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<!-- jQuery -->
	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<!-- jquery.cookie -->
	<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
	<!-- layer -->
	<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
	<!-- vue -->
	<script src="http://cdn.jsdelivr.net/vue/1.0.7/vue.min.js"></script>
	<script src="../../../layui/layui.js"></script>
	<script src="../../../js/byking.js"></script>
	<script src="../../../js/hostconfig.js"></script>

	<script>

	function initpage(){
		var guid = $byking.getUrlParam("guid");
		var url = $hostconfig.sysAuthHost+"/department/info?guid="+guid;
		$byking.getJSONWithToken(url,function(data){
			var info = data.data;
			$("#name").val(info.name);
			$("#guid").val(info.guid);
			$("#description").val(info.description);
			$("#image").val(info.image);
		},function(data){});
	}
		
	var submitflag = true;
	layui.use('form', function() {
		var form = layui.form();
		//监听提交
		form.on('submit(formDemo)', function(data) {
			$(".layui-btn").addClass("layui-btn-disabled");
			var data = data.field;
			if(!submitflag){
				return false;
			}
			submitflag = false;
			var url = $hostconfig.sysAuthHost+"/department/add";
			data.update_by = $byking.getCookieValue("user_guid");
			$byking.postJSONWithToken(url,data,function(obj){
				layer.msg("修改成功");
				var index = parent.layer.getFrameIndex(window.name);
				parent.refrehDepartmentTree(data);
				parent.layer.close(index);
			},function(data){});
			return false;
		});
	});
	</script>
</body>
</html>